package com.comdo.newup_loan.module.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.comdo.newup_loan.R;
import com.comdo.newup_loan.base.BaseActivity;
import com.comdo.newup_loan.comom.Config;
import com.comdo.newup_loan.util.StringUtils;
import com.comdo.newup_loan.util.TitleMenuUtil;
import com.umeng.analytics.MobclickAgent;

import butterknife.BindView;

/**
 * Created by liyuan on 2017/11/2.
 */

public class WantLoanActivity extends BaseActivity<WantLoanPresenter> implements WantLoanContract.View {
    @BindView(R.id.ed_name)
    TextView mNameText;
    @BindView(R.id.ed_phone)
    TextView mPhoneText;
    @BindView(R.id.btn_submit)
    Button mSubmitBtn;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_wantloan;
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        new TitleMenuUtil(WantLoanActivity.this, "我要借款", true);
        mSubmitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(StringUtils.isNull(mNameText.getText().toString())){
                    showToast("姓名不能为空！");
                    return;
                }
                if(StringUtils.isNull(mPhoneText.getText().toString())){
                    showToast("联系号码不能为空！");
                    return;
                }
                if(!StringUtils.isMobile(mPhoneText.getText().toString())){
                    showToast("请填写正确的手机号码！");
                    return;
                }
                   mPresenter.sumbit(Config.loginInfo.getUserId(),mNameText.getText().toString(),mPhoneText.getText().toString());
            }
        });
    }

    @Override
    protected boolean translucentStatusBar() {
        return super.translucentStatusBar();
    }

    @Override
    public WantLoanPresenter getmPresenter() {
        return new WantLoanPresenter();
    }

    @Override
    public void presenterSetView() {
        if (mPresenter != null)
            mPresenter.setView(this);
    }

    @Override
    public void getFail(String failMessage) {
        showToast(failMessage);
    }

    @Override
    public void success(String Message) {
        showToast(Message);
        toSuccessActivity();
    }
    private void toSuccessActivity(){
        Intent intent=new Intent(WantLoanActivity.this, WantLoanSuccessActivity.class);
        startActivity(intent);
        this.finish();
    }
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("我要借款");
        MobclickAgent.onResume(this);
    }
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("我要借款");
        MobclickAgent.onPause(this);
    }
}
